/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ejb;

import entity.User;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author user
 */
@Stateless

public class Loginejb {

    @PersistenceContext(unitName = "meteocalpersist")
    EntityManager em;

    User user;

    public User checkLogged(String name, String password) {
        user = em.find(User.class, name);
        if (user != null) {
            if (user.getPassword().equals(password)) {
                return user;
            }
        }

        return null;
    }

    public String loggedUser() {
        if (user != null) {
            System.out.print("logged user with username is: " + user.getUsername());
            return user.getUsername();
        } else {
            return null;
        }
    }

}

